home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / SideScroller / Layer.as < prev    next >
Text File  |  2007-09-27  |  12KB  |  398 lines

  1. class SideScroller.Layer extends Library.DispatcherBase
  2. {
  3.    static var TYPE_STATIC = 1;
  4.    static var TYPE_MOVING = 2;
  5.    static var METHOD_ORDERED = 1;
  6.    static var METHOD_RANDOM = 2;
  7.    static var DEPTH_PANEL_MIN = 1;
  8.    static var DEPTH_PANEL_MAX = 50000;
  9.    static var DEPTH_OBJECT_MIN = 1;
  10.    static var DEPTH_OBJECT_MAX = 50000;
  11.    static var DEPTH_FRONT_MIN = 55000;
  12.    static var DEPTH_FRONT_MAX = 75000;
  13.    static var DEPTH_REMOVE_MIN = 100000;
  14.    static var DEPTH_REMOVE_MAX = 110000;
  15.    static var GROUND_CHECK_MODIFIER = 50;
  16.    static var MAX_HEIGHT = 400;
  17.    function Layer(__oLayerID, __mcRef, __nLayerType, __nAttachMethod, __oSSInstance)
  18.    {
  19.       super();
  20.       this.mcRef = __mcRef;
  21.       this.oSSInstance = __oSSInstance;
  22.       this.mcRef.createEmptyMovieClip("mcPanels",1);
  23.       this.mcRef.createEmptyMovieClip("mcObjects",2);
  24.       this.mcRef.mcPanels.lineStyle(0,0,0);
  25.       this.mcRef.mcPanels.lineTo(1,1);
  26.       this.mcRef.mcObjects.lineStyle(0,0,0);
  27.       this.mcRef.mcObjects.lineTo(1,1);
  28.       this.nLayerType = __nLayerType;
  29.       this.nAttachMethod = __nAttachMethod;
  30.       this.oLayerID = __oLayerID;
  31.       this.nNextPanelDepth = SideScroller.Layer.DEPTH_PANEL_MIN;
  32.       this.nNextObjectDepth = SideScroller.Layer.DEPTH_OBJECT_MIN;
  33.       this.nNextRemoveDepth = SideScroller.Layer.DEPTH_REMOVE_MIN;
  34.       this.nNextFrontDepth = SideScroller.Layer.DEPTH_FRONT_MIN;
  35.       if(this.nLayerType == SideScroller.Layer.TYPE_STATIC)
  36.       {
  37.          this.nParalaxRatioX = 0;
  38.          this.nParalaxRatioY = 0;
  39.       }
  40.       else
  41.       {
  42.          this.nParalaxRatioX = 1;
  43.          this.nParalaxRatioY = 1;
  44.       }
  45.       this.nOverLap = 0;
  46.       this.bFirstPanel = true;
  47.       this.aPanelsLinkages = new Array();
  48.       this.aPanelsVisual = new Array();
  49.       this.aObjects = new Array();
  50.       this.nFloorHeight = Infinity;
  51.       this.oSSInstance.doAddListener(this);
  52.    }
  53.    function doEnterFrame()
  54.    {
  55.       super.doEnterFrame();
  56.       if(this.nLayerType == SideScroller.Layer.TYPE_MOVING)
  57.       {
  58.          this.doCheckLooping();
  59.       }
  60.    }
  61.    function setOverlap(__n)
  62.    {
  63.       this.nOverLap = __n;
  64.    }
  65.    function doAddPanelLinkage(sLinkage)
  66.    {
  67.       this.aPanelsLinkages.push(sLinkage);
  68.       if(this.bFirstPanel)
  69.       {
  70.          this.doAddPanel();
  71.          this.bFirstPanel = false;
  72.       }
  73.    }
  74.    function doAddPanelLinkageSet(aPanelsLinkagesLinkage)
  75.    {
  76.       var _loc2_ = undefined;
  77.       _loc2_ = 0;
  78.       while(_loc2_ <= aPanelsLinkagesLinkage.length - 1)
  79.       {
  80.          this.doAddPanelLinkage(aPanelsLinkagesLinkage[_loc2_]);
  81.          _loc2_ = _loc2_ + 1;
  82.       }
  83.    }
  84.    function doAttachVisual(__sLinkage)
  85.    {
  86.       do
  87.       {
  88.          this.nNextObjectDepth = this.nNextObjectDepth + 1;
  89.          if(this.nNextObjectDepth > SideScroller.Layer.DEPTH_FRONT_MAX)
  90.          {
  91.             this.nNextObjectDepth = SideScroller.Layer.DEPTH_FRONT_MIN;
  92.          }
  93.       }
  94.       while(this.mcRef.mcObjects.getInstanceAtDepth(this.nNextObjectDepth) != undefined);
  95.       
  96.       var _loc2_ = this.mcRef.mcObjects.attachMovie(__sLinkage,"mcObject_" + __sLinkage + "_" + this.nNextObjectDepth,this.nNextObjectDepth);
  97.       return _loc2_;
  98.    }
  99.    function doPutInFront(__mc)
  100.    {
  101.       do
  102.       {
  103.          this.nNextFrontDepth = this.nNextFrontDepth + 1;
  104.          if(this.nNextFrontDepth > SideScroller.Layer.DEPTH_FRONT_MAX)
  105.          {
  106.             this.nNextFrontDepth = SideScroller.Layer.DEPTH_FRONT_MIN;
  107.          }
  108.       }
  109.       while(__mc._parent.getInstanceAtDepth(this.nNextFrontDepth) != undefined);
  110.       
  111.       __mc.swapDepths(this.nNextFrontDepth);
  112.    }
  113.    function doAddObject(__oObject)
  114.    {
  115.       this.aObjects.push(__oObject);
  116.    }
  117.    function doRemoveObject(__oObject)
  118.    {
  119.       if(this.aObjects.length > 0)
  120.       {
  121.          for(var _loc3_ in this.aObjects)
  122.          {
  123.             if(this.aObjects[_loc3_] == __oObject)
  124.             {
  125.                delete this.aObjects[_loc3_];
  126.                this.aObjects.splice(Number(_loc3_),1);
  127.             }
  128.          }
  129.       }
  130.    }
  131.    function getCollidableObjects(__oRequester)
  132.    {
  133.       var _loc9_ = new Array();
  134.       var _loc7_ = __oRequester.__get__Coord();
  135.       var _loc3_ = undefined;
  136.       _loc3_ = 0;
  137.       while(_loc3_ <= this.aObjects.length - 1)
  138.       {
  139.          if(this.aObjects[_loc3_] != __oRequester)
  140.          {
  141.             var _loc2_ = this.aObjects[_loc3_];
  142.             if(_loc2_.__get__Hitable() && _loc2_.__get__ObjectBlock())
  143.             {
  144.                var _loc4_ = _loc2_.__get__Coord();
  145.                var _loc5_ = Library.Utils.MoreMath.getDistance(_loc4_.x,_loc4_.y,_loc7_.x,_loc7_.y);
  146.                var _loc6_ = _loc2_.__get__HitDistance() + __oRequester.__get__HitDistance();
  147.                if(Math.abs(_loc5_) <= _loc6_)
  148.                {
  149.                   _loc9_.push(_loc2_);
  150.                }
  151.             }
  152.          }
  153.          _loc3_ = _loc3_ + 1;
  154.       }
  155.       return _loc9_;
  156.    }
  157.    function getGroundObjects(__oRequester)
  158.    {
  159.       var _loc4_ = new Array();
  160.       var _loc2_ = undefined;
  161.       _loc2_ = 0;
  162.       while(_loc2_ <= this.aObjects.length - 1)
  163.       {
  164.          if(this.aObjects[_loc2_] != __oRequester)
  165.          {
  166.             var _loc3_ = this.aObjects[_loc2_];
  167.             if(_loc3_.__get__GroundModifier())
  168.             {
  169.                _loc4_.push(_loc3_);
  170.             }
  171.          }
  172.          _loc2_ = _loc2_ + 1;
  173.       }
  174.       return _loc4_;
  175.    }
  176.    function getSpecialObjects(__oRequester)
  177.    {
  178.       var _loc9_ = new Array();
  179.       var _loc7_ = __oRequester.__get__Coord();
  180.       var _loc3_ = undefined;
  181.       _loc3_ = 0;
  182.       while(_loc3_ <= this.aObjects.length - 1)
  183.       {
  184.          if(this.aObjects[_loc3_] != __oRequester)
  185.          {
  186.             var _loc2_ = this.aObjects[_loc3_];
  187.             if(_loc2_.__get__Hitable() && _loc2_.__get__ObjectSpecial())
  188.             {
  189.                var _loc4_ = _loc2_.__get__Coord();
  190.                var _loc5_ = Library.Utils.MoreMath.getDistance(_loc4_.x,_loc4_.y,_loc7_.x,_loc7_.y);
  191.                var _loc6_ = _loc2_.__get__HitDistance() + __oRequester.__get__HitDistance();
  192.                if(Math.abs(_loc5_) <= _loc6_)
  193.                {
  194.                   _loc9_.push(_loc2_);
  195.                }
  196.             }
  197.          }
  198.          _loc3_ = _loc3_ + 1;
  199.       }
  200.       return _loc9_;
  201.    }
  202.    function getFloorAt(__nPositionX, __nPositionY, __oRequester)
  203.    {
  204.       var _loc5_ = this.nFloorHeight;
  205.       var _loc7_ = new Array();
  206.       var _loc10_ = this.getGroundObjects(SideScroller.BasicObject(__oRequester));
  207.       var _loc2_ = undefined;
  208.       _loc2_ = 0;
  209.       while(_loc2_ <= _loc10_.length - 1)
  210.       {
  211.          var _loc6_ = _loc10_[_loc2_].GroundObject;
  212.          if(_loc6_.StartPos <= __nPositionX && _loc6_.EndPos >= __nPositionX)
  213.          {
  214.             if(_loc6_ instanceof SideScroller.Ground)
  215.             {
  216.                var _loc4_ = _loc6_.getGroundAt(__nPositionX);
  217.                var _loc3_ = true;
  218.                if(_loc4_ > _loc5_)
  219.                {
  220.                   _loc3_ = false;
  221.                }
  222.                else if(__oRequester.__get__Speeds().y < 0)
  223.                {
  224.                   _loc3_ = false;
  225.                }
  226.                else if(_loc4_ < __nPositionY - __oRequester.__get__CliffClimbCapacity() - __oRequester.__get__Speeds().y)
  227.                {
  228.                   _loc3_ = false;
  229.                }
  230.                if(_loc3_)
  231.                {
  232.                   _loc5_ = _loc4_;
  233.                }
  234.             }
  235.             else if(_loc6_ instanceof SideScroller.NegativeGround)
  236.             {
  237.                _loc7_.push(_loc6_);
  238.             }
  239.          }
  240.          _loc2_ = _loc2_ + 1;
  241.       }
  242.       if(_loc5_ == this.nFloorHeight)
  243.       {
  244.          _loc2_ = 0;
  245.          while(_loc2_ <= _loc7_.length - 1)
  246.          {
  247.             _loc6_ = _loc7_[_loc2_];
  248.             if(_loc6_.getGroundAt() > _loc5_)
  249.             {
  250.                _loc5_ = _loc6_.getGroundAt();
  251.             }
  252.             _loc2_ = _loc2_ + 1;
  253.          }
  254.       }
  255.       return _loc5_;
  256.    }
  257.    function doMoveTo(__nX, __nY)
  258.    {
  259.       this.mcRef._x = __nX * this.nParalaxRatioX;
  260.       this.mcRef._y = __nY * this.nParalaxRatioY;
  261.    }
  262.    function getRemoveDepth(__mc)
  263.    {
  264.       do
  265.       {
  266.          this.nNextRemoveDepth = this.nNextRemoveDepth + 1;
  267.          if(this.nNextRemoveDepth > SideScroller.Layer.DEPTH_REMOVE_MAX)
  268.          {
  269.             this.nNextRemoveDepth = SideScroller.Layer.DEPTH_REMOVE_MIN;
  270.          }
  271.       }
  272.       while(__mc._parent.getInstanceAtDepth(this.nNextRemoveDepth) != undefined);
  273.       
  274.       return this.nNextRemoveDepth;
  275.    }
  276.    function doDestroy()
  277.    {
  278.       this.oSSInstance.doRemoveListener(this);
  279.       for(var _loc3_ in this.aPanelsVisual)
  280.       {
  281.          this.doRemoveObjectsIn(this.aPanelsVisual[_loc3_]);
  282.       }
  283.       for(_loc3_ in this.aObjects)
  284.       {
  285.          this.aObjects[_loc3_].doDestroy();
  286.       }
  287.       delete this.aPanelsVisual;
  288.       delete this.aObjects;
  289.       delete this.oSSInstance;
  290.       this.mcRef.swapDepths(this.getRemoveDepth(this.mcRef));
  291.       this.mcRef.removeMovieClip();
  292.       delete this.mcRef;
  293.       super.doDestroy();
  294.    }
  295.    function get AllObjects()
  296.    {
  297.       return Library.Utils.Tools.doCopyArray(this.aObjects);
  298.    }
  299.    function get Id()
  300.    {
  301.       return this.oLayerID;
  302.    }
  303.    function get PanelsWidth()
  304.    {
  305.       return this.mcRef.mcPanels._width;
  306.    }
  307.    function get PanelsHeight()
  308.    {
  309.       return Math.min(this.mcRef.mcPanels._height,SideScroller.Layer.MAX_HEIGHT);
  310.    }
  311.    function get PanelsRef()
  312.    {
  313.       return this.__get__Ref().mcPanels;
  314.    }
  315.    function get Ref()
  316.    {
  317.       return this.mcRef;
  318.    }
  319.    function set ParalaxRatioX(__nParalaxRatioX)
  320.    {
  321.       this.nParalaxRatioX = __nParalaxRatioX;
  322.    }
  323.    function set ParalaxRatioY(__nParalaxRatioY)
  324.    {
  325.       this.nParalaxRatioY = __nParalaxRatioY;
  326.    }
  327.    function set BaseFloor(__nFloorHeight)
  328.    {
  329.       this.nFloorHeight = __nFloorHeight;
  330.    }
  331.    function doCheckLooping()
  332.    {
  333.       var _loc2_ = this.__get__PanelsWidth() + this.mcRef._x;
  334.       if(_loc2_ <= this.oSSInstance.__get__StageWidth() + SideScroller.SideScrollerManager.LOOP_BUFFER)
  335.       {
  336.          this.doAddPanel(this.__get__PanelsWidth());
  337.       }
  338.       this.doCheckForPanelRemoval();
  339.    }
  340.    function doAddPanel(__nPosition)
  341.    {
  342.       var _loc3_ = undefined;
  343.       var _loc2_ = undefined;
  344.       switch(this.nAttachMethod)
  345.       {
  346.          case SideScroller.Layer.METHOD_ORDERED:
  347.             if(this.aPanelsLinkages.length > 0)
  348.             {
  349.                _loc3_ = String(this.aPanelsLinkages.shift());
  350.                _loc2_ = true;
  351.             }
  352.             else
  353.             {
  354.                _loc2_ = false;
  355.             }
  356.             break;
  357.          case SideScroller.Layer.METHOD_RANDOM:
  358.             var _loc5_ = Library.Utils.MoreMath.getRandomRange(0,this.aPanelsLinkages.length - 1);
  359.             _loc3_ = this.aPanelsLinkages[_loc5_];
  360.             _loc2_ = true;
  361.       }
  362.       if(_loc2_)
  363.       {
  364.          var _loc4_ = this.mcRef.mcPanels.attachMovie(_loc3_,"mcPanel" + this.nNextPanelDepth,this.nNextPanelDepth);
  365.          _loc4_._x = __nPosition - this.nOverLap;
  366.          this.aPanelsVisual.push(_loc4_);
  367.          this.nNextPanelDepth = this.nNextPanelDepth + 1;
  368.          if(this.nNextPanelDepth > SideScroller.Layer.DEPTH_PANEL_MAX)
  369.          {
  370.             this.nNextPanelDepth = SideScroller.Layer.DEPTH_PANEL_MIN;
  371.          }
  372.       }
  373.    }
  374.    function doRemoveObjectsIn(__mcContainer)
  375.    {
  376.       var _loc2_ = undefined;
  377.       for(_loc2_ in this.aObjects)
  378.       {
  379.          if(String(this.aObjects[_loc2_].Ref).indexOf(String(__mcContainer)) != -1)
  380.          {
  381.             this.aObjects[_loc2_].doDestroy();
  382.          }
  383.       }
  384.    }
  385.    function doCheckForPanelRemoval()
  386.    {
  387.       var _loc2_ = this.aPanelsVisual[0];
  388.       var _loc3_ = undefined;
  389.       _loc3_ = _loc2_._x + _loc2_._width + this.mcRef._x;
  390.       if(_loc3_ < - SideScroller.SideScrollerManager.LOOP_BUFFER)
  391.       {
  392.          this.doRemoveObjectsIn(_loc2_);
  393.          _loc2_.removeMovieClip();
  394.          this.aPanelsVisual.shift();
  395.       }
  396.    }
  397. }
  398.